<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script type="text/javascript">
  // bind

  var obj = {
    name:'zs',
    fun : function(){
      setInterval(function(){
        console.log(this.name);
      },1000)
    }
  }

  obj.fun()  // 打印的是空字符串，因为定时器中function的this指向window

  var obj2 = {
    name:'zs',
    fun : function(){
      setInterval(function(){
        console.log(this.name);
      }.bind(this),1000)
    }
  }

  obj2.fun()  // zs

  btn.onclick = function(){
    // 事件处理函数中的this是触发该事件的对象
  }.bind(obj)
    // 通过bind改变事件处理函数中的this

  </script>
</body>
</html>